<?php
include '../../../wp-blog-header.php';
require_once( ABSPATH . WPINC . '/registration.php');
if('POST' != $_SERVER['REQUEST_METHOD'])die('not post');
$user_email = $_POST['user_email'];

$user_login = strtolower($_POST['firstname']).strtolower($_POST['lastname']);

if(!is_email( $user_email ))
{
  die('Please enter a valid email address');
}elseif( email_exists( $user_email )){
  die('Please enter another email address, email exists already');
}

if(username_exists( $user_login ))
{
  $user_login = $user_login.'1';
}

$random_password = wp_generate_password( 12, false );
$user_id = wp_create_user( $user_login, $random_password, $user_email );

if ( !$user_id )die('bad user_id');
wp_new_user_notification($user_id, $random_password);

echo 'Registration Successful, Please Check Your Email';
//print_r($_POST);
?>